/** 提供登录的账号列表，点击注入按钮，对应账号会自动填充至登录表单中 */

/**
 * 特定成员权限
 * 
 * 部门权限
 * 
 * 岗位权限
 */
import { items, ItemProp } from '@/pages/home/items';
import { RootAuthy } from '@/config/userAuthy/rootAuthy';
import { CommonAuthy } from '@/config/userAuthy/commonAuthy';
import { cloneDeep } from 'lodash';

/**
 * 合并导航 将authy添加到导航
 */
function combineRoute(auth: ItemProp[]) {
    const result: ItemProp[] = cloneDeep(items);

    function combine(authyList: ItemProp[], itemList: ItemProp[]) {
        itemList.forEach((v, i) => {
            itemList[i].authy = authyList[i].authy;

            if (v.children) {
                combine(authyList[i].children, itemList[i].children);
            }
        })
    }

    combine(auth, result);

    return result;
}

export interface AccountType {
    key: string; // 唯一标识
    username: string; // 账号
    password: string; // 密码
    limits: string[]; // 权限
    role?: any;
}

export const accountsList: AccountType[] = [
    {
        key: 'root',
        username: 'admin',
        password: '123',
        limits: ['read', 'write'],
        role: combineRoute(RootAuthy),
    },
    {
        key: 'visitor',
        username: 'visitor',
        password: '123',
        limits: ['readonly'],
        role: combineRoute(CommonAuthy),
    },
];

/** 不同的权限，显示不同颜色的标签 */
export const limitTagColor = (limit: string): string => {
    switch (limit) {
        case 'read':
            return 'green';
        case 'write':
            return 'volcano';
        default:
            return 'geekblue'
    }
};
